﻿@model IEnumerable<Quiz.Model.Question>

@{
    ViewBag.Title = "Manage Questions";
    ViewBag.Menu = "Play.Index";
}
<style>
    table {
        padding: 0;
        margin: 0;
    }

    th {
        border: 2px solid #445566;
        padding: 0;
        margin: 0;
    }

    td {
        border: 1px solid #778899;
        padding: 0;
        margin: 0;
    }

    .answerset {
        background-color: #ededed;
    }

        .answerset q {
            float: left;
        }

        .answerset r {
            float: right;
        }

    .line {
        display: block;
        margin-top: 10px;
    }
</style>
<h2>List of Questions</h2>

<p>
    @{
        var createPage = Url.Action("Create");
    }
    <button onclick="window.location.href='@createPage'">Create Question</button>
</p>
<ul id="sortable">
    @foreach (var item in Model)
    {
        string anstext = "A";
        <li>
            <div class="line">
                @Html.DisplayFor(modelItem => item.QuestionText)
            </div>

            <div class="line">
                @if (item != null && !string.IsNullOrEmpty(item.AnswerDom))
                {
                    List<Quiz.Model.AnswerSet> answers = item.GetPossibleAnswers();
                    if (answers.Any())
                    {
                    <div>
                        @foreach (Quiz.Model.AnswerSet ans in item.GetPossibleAnswers())
                        {
                            if (ans.AnswerSetID == item.AnswerRowID)
                            {
                                anstext = ans.Position.ToString();
                            }
                            <div class="answerset">

                                @ans.Position
                                |
                                    @ans.Text

                            </div>
                        }
                    </div>
     
                    }
                    else
                    {
                    <div>
                        No Answer Registered
                    </div>
                    }
                }
                else
                {
                    <div>
                        No Answer Registered
                    </div>
                }
            </div>
            <div class="line">
                ANS.  @anstext
            </div>
            <div class="line">
                @{
                var editPage = Url.Action("Edit", new { id = item.RowKey });
                }
                <button onclick="window.location.href='@editPage'">Edit Question</button>
            </div>
            <div class="line">
                @{
                var deletePage = Url.Action("Delete", new { id = item.RowKey });
                }
                <button onclick="window.location.href='@deletePage'">Delete Question</button>
            </div>
        </li>
    }
</ul>

